package com.sdehua.wear.controller;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.sdehua.wear.entity.User;
import com.sdehua.wear.service.UserService;
import com.sdehua.wear.utils.ResultEntity;
import lombok.extern.log4j.Log4j2;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.print.attribute.standard.RequestingUserName;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2021-12-31 15:30:06
 */
@RestController
@RequestMapping("user")
@CrossOrigin
@Log4j2
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public User selectOne(Integer id) {
        return this.userService.queryById(id);
    }

    @RequestMapping("login")
    public ResultEntity login(@RequestBody Map<String,Map<String,String>> user){
        User login = userService.login(user);
        if (Objects.equals(login,null)) {
            return ResultEntity.fail("用户名/密码错误");
        }
        return ResultEntity.success(login);
    }

}